package com.jurenzhao.partssystem.system.system_user.controller;


import com.jurenzhao.partssystem.system.system_log.aspect.annotation.Token;
import com.jurenzhao.partssystem.system.system_log.entity.System_Log;
import com.jurenzhao.partssystem.system.system_log.service.LogService;
import com.jurenzhao.partssystem.system.system_log.util.MyLog;
import com.jurenzhao.partssystem.system.system_user.entity.System_Users;

import com.jurenzhao.partssystem.system.system_user.service.System_UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/system_user")
public class System_UserController {
    @Resource()
    private System_UserService system_userService;
    @Resource
    private LogService system_logService;
    @RequestMapping("/login")
    public String login(String user_no, String user_pass, Model model,HttpServletRequest request,HttpSession session){
        session.setAttribute("user_no",user_no);
        System_Users system_users = system_userService.login(user_no,user_pass);
        if (system_users != null){
            model.addAttribute("system_useres",system_users);
            MyLog mylog = new MyLog();
            session.setAttribute("system_users",system_users);
            return "index";
        }else {
            model.addAttribute("msg","用户名或密码错误");
            return "login";
        }
    }
    @RequestMapping("/main")
    public String sss(){
        return "main";
    }
    @RequestMapping("/auth")
    public String auth(){
        return "System/user";
    }
    @RequestMapping("/contract")
    public String contract(){
        return "System/contract";
    }
    @RequestMapping("/log")
    public String log(Model model){
        List<System_Log> system_logs = system_logService.findAll();
        model.addAttribute("system_logs",system_logs);
        return "System/log";
    }

    @RequestMapping("/parameter")
    public String parameter(Model model,HttpSession session){
        System_Users system_users = (System_Users) session.getAttribute("system_users");
        model.addAttribute("system_users",system_users);
        return "System/parameter";
    }
    @RequestMapping("/user")
    public String user(){
        return "System/user";
    }


}
